package com.ycyoes.biz.dataprocess.shaomeng;

import com.ycyoes.demos.test.text.HandleText;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DuplicateMerge {
    public static void main(String[] args) {
        List<String> list = HandleText.readFile("e:/company.csv");
        Map<String, String> map = new HashMap<>(); //存储原始数据，key: 单位名称， value: 年份
        for (int i = 0; i < list.size(); i++) {
            String[] content = list.get(i).split(",");
//            System.out.println(list.get(i));
//            System.out.println("content: " + content[0] + " ----- " + content[4]);
            String key = content[4];
            String value = content[0];
            if (map.containsKey(key)) {
                map.put(key, map.get(key) + (map.get(key).indexOf(value) > -1 ? "" : "," + value));
            } else {
                map.put(key, value);
            }
        }
        map.forEach((key, value) -> {
//            System.out.println(key + "  " + value);
        });
//        System.out.println("=============================================");
        for (int i = 0; i < list.size(); i++) {
            String[] content = list.get(i).split(",");
            String key = content[4];
            System.out.println(list.get(i)  + "," + map.get(key));

        }
    }
}
